package com.xcx.robot;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.xcx.robot.mirai.entity.JX3API;
import com.xcx.robot.mirai.jxapi.Result;
import com.xcx.robot.mirai.jxapi.ResultData;
import com.xcx.robot.mirai.key.KeyWord;
import com.xcx.robot.util.DateUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import ws.schild.jave.Encoder;
import ws.schild.jave.MultimediaObject;
import ws.schild.jave.encode.AudioAttributes;
import ws.schild.jave.encode.EncodingAttributes;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @Author: 邢晨旭
 * @Date: 2021/5/28 18:42
 * @Description:
 */
@Data
@Slf4j
public class Test {

    private String profession = "https://jx3kt.oss-cn-shanghai.aliyuncs.com/jy.png";
    private String name = "一共个字啊";

    private static final int width = 500;

    private static final int height = 292;

    public static void openServer(String server) {
        //得到图片缓冲区
        FileInputStream fileInputStream = null;
        try {
            BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
//            File file = new File("bg.jpeg");
//            if (!file.exists()) {
//                throw new Exception("背景存放地址有误");
//            }
//            fileInputStream = new FileInputStream(file);
//            BufferedImage image2 = ImageIO.read(fileInputStream);
            //得到它的绘制环境(这张图片的笔)
            Graphics2D g2 = (Graphics2D) bi.getGraphics();
            //消除文字锯齿
            g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

//消除画图锯
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

            g2.fillRect(0, 0, width, height);
            //设置颜色
            g2.setColor(Color.WHITE);
            // 将图片大小设置为大约4cm*4cm 具体根据纸张大小设定
//            g2.drawImage(image2, 0, 0, 500, 292, null);
            g2.drawRect(0, 0, width - 1, height - 1);
            //设置字体:字体、字号、大小
            g2.setFont(new Font("黑体", Font.BOLD, 20));
            g2.setPaint(new Color(203, 167, 3, 64));//阴影颜色
            g2.drawString(server, 110, 150);//先绘制阴影
            //设置背景颜色
            g2.setColor(Color.ORANGE);
            //向图片上写字符串
            g2.drawString(server, 110, 150);

            g2.setPaint(new Color(0, 0, 0, 64));//阴影颜色
            g2.drawString(server, 110, 150);//先绘制阴影
            g2.setColor(Color.black);
            g2.drawString(server, 110, 170);
            // 图片上传后的路径
            String savePath = "test.jpg";
            ImageIO.write(bi, "JPEG", new FileOutputStream(savePath));
        } catch (Exception e) {
            log.error("", e);
        }
    }

    public static void test(String server) {
        //得到图片缓冲区
        FileInputStream fileInputStream = null;
        try {
            BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            File file = new File("img/bg.jpeg");
            if (!file.exists()) {
                throw new Exception("背景存放地址有误");
            }
            fileInputStream = new FileInputStream(file);
            BufferedImage image2 = ImageIO.read(fileInputStream);
            //得到它的绘制环境(这张图片的笔)
            Graphics2D g2 = (Graphics2D) bi.getGraphics();
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.fillRect(0, 0, width, height);
            //设置颜色
            g2.setColor(Color.WHITE);
            // 将图片大小设置为大约4cm*4cm 具体根据纸张大小设定
            g2.drawImage(image2, 0, 0, 500, 292, null);
            g2.drawRect(0, 0, width - 1, height - 1);
            g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            //设置字体:字体、字号、大小
            g2.setFont(new Font("黑体", Font.BOLD, 20));
            g2.setPaint(new Color(0, 0, 0, 64));//阴影颜色
            g2.drawString(server, 110, 150);//先绘制阴影
            //设置背景颜色
            g2.setColor(Color.BLACK);
            //向图片上写字符串
            g2.drawString(server, 110, 150);
            g2.setPaint(new Color(0, 0, 255, 64));//阴影颜色
            g2.drawString("开服啦", 200, 150);
            g2.setFont(new Font("黑体", Font.BOLD, 20));
            g2.setColor(Color.blue);
            g2.drawString("开服啦", 200, 150);
            g2.setFont(new Font("黑体", Font.BOLD, 15));
            g2.setPaint(new Color(0, 2, 255, 64));//阴影颜色
            g2.drawString(DateUtils.getDateTime(), 110, 170);
            g2.setColor(Color.blue);
            g2.drawString(DateUtils.getDateTime(), 110, 170);
            g2.dispose();
            String savePath = "test.jpg";
            ImageIO.write(bi, "JPEG", new FileOutputStream(savePath));
        } catch (Exception e) {
            log.error("开服监控图片生成出错", e);
        }
    }


    public static void main(String[] args) throws Exception {
//        File source = new File("test.wav");
//        File target = new File("test.amr");
//
//        //Audio Attributes
//        AudioAttributes audio = new AudioAttributes();
//        audio.setCodec("libopencore_amrnb");
//        audio.setBitRate(64000);
//        audio.setChannels(1);
//        audio.setSamplingRate(8000);
//
//        //Encoding attributes
//        EncodingAttributes attrs = new EncodingAttributes();
//        attrs.setInputFormat("wav");
//        attrs.setOutputFormat("amr");
//        attrs.setAudioAttributes(audio);
//        //Encode
//        Encoder encoder = new Encoder();
//        encoder.encode(new MultimediaObject(source), target, attrs);
        String daily = HttpUtil.get(JX3API.DAILY);
        System.out.println(daily);
        Result result = JSONObject.parseObject(daily, Result.class);
        ResultData data = result.getData();
        System.out.println(data);
    }


}


